<?php

/*
 * Action 2$
 * 
 * +1$
 * Choose one: +2 Actions; or +2 Buys; or gain a Silver.
 * When you trash this, gain an Attack card.
 *
 */

class Squire extends Card implements iAction, iKingdom, iDarkAges {

    public function __construct() {
        parent::__construct("Squire", 2);
        $this->undoPlay = false;
        $this->undoBuy = true;
    }

    public function getDescription() {
        return array(
            "+1$",
            "Choose one: +2 Actions; or +2 Buys; or gain a Silver.",
            "When you trash this, gain an Attack card.");
    }

    public function trash(Game $game, $name) {
        $boardCards = $game->getBoardCardsByPrice();
        $attacks = array();
        foreach ($boardCards as $card) {
            if ($card instanceof iAttack) {
                $attacks[] = $card;
            }
        }
        if (sizeof($attacks) == 0) {
            ScreenDisplay::addScreenMessage($game, true, "gain nothing", " gains nothing", $name);
        } elseif (sizeof($attacks) == 1) {
            $card = $game->moveCardFromPileToPile($attacks[0], BoardCards, DiscardPile, $name);
            ScreenDisplay::addScreenMessage($game, true, "gain " . nicePrint($card), " gains " . ScreenDisplay::$LMSG, $name);
        } else {
            $output = MySocket::GetUserReply($game, Input_ChooseOne, $options, 1, 1, null, "Please choose attack to gain", $name);
            $card = $game->moveCardFromPileToPile($output[0], BoardCards, DiscardPile, $name);
            ScreenDisplay::addScreenMessage($game, true, "gain " . nicePrint($card), " gains " . ScreenDisplay::$LMSG, $name);
        }
        $game->setTempCard($this);
        $game->cardTrashFinished($name);
    }

    public function play(Game $game, $isRealCard) {
        $game->addMoney(new Price(1));
        ScreenDisplay::addScreenMessage($game, true, " get +1$", "gets +1$");

        $options = array(new Option(1, "2 actions"), new Option(2, "2 buy"), new Option(3, "Gain a Silver"));
        $output = MySocket::GetUserReply($game, Input_ChooseOne, $options, 1, 1, null, "Please choose");
        $answer = $output[0];
       
        if ($answer == "2 actions") {
            $game->addActions(2);
            ScreenDisplay::addScreenMessage($game, false, " and +2 actions", " and +2 actions");
        } elseif ($answer == "2 buy") {
            $game->addBuys(2);
            ScreenDisplay::addScreenMessage($game, false, " and +2 buy", " and +2 buy");
        } else {
            $s = $game->moveCardFromPileToPile("Silver", BoardCards, DiscardPile);
            ScreenDisplay::addScreenMessage($game, false, " and gain " . nicePrint($s), " and gains " . ScreenDisplay::$LMSG);
        }
        $game->cardActionFinished();
        return true;
    }

}

?>